<?php 
	require_once (dirname(__FILE__) . '/Autoloader.php');

	Xiaoler\Blade\Autoloader::register();	
	use Xiaoler\Blade\FileViewFinder;
	use Xiaoler\Blade\Factory;
	use Xiaoler\Blade\Compilers\BladeCompiler;
	use Xiaoler\Blade\Engines\CompilerEngine;
	use Xiaoler\Blade\Filesystem;
	use Xiaoler\Blade\Engines\EngineResolver;

	class Blade{
	//protected $viewpath;
	//protected $cachePath;
	protected $blade;
	public function __construct($view_path,$cache_path)
	{
		//$this->cachepath = $cache_path;
		//$this->viewpath = $view_path;
		$file = new Filesystem;
		$compiler = new BladeCompiler($file, $cache_path);

		// you can add a custom directive if you want
		$compiler->directive('datetime', function($timestamp) {
		    return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
		});

		$resolver = new EngineResolver;
		$resolver->register('blade', function () use ($compiler) {
		    return new CompilerEngine($compiler);
		});

		// get an instance of factory
		$factory = new Factory($resolver, new FileViewFinder($file, $view_path));

		// if your view file extension is not php or blade.php, use this to add it
		$factory->addExtension('tpl', 'blade');
		$this->blade = $factory;
		//$vv = get_class_methods($apps);
		//var_dump($apps->viewPath());
		//return $factory;

	}
	public function make($tpl='index',$data=[])
	{
		//return "stringsssss";
		
		 echo $this->blade->make($tpl, $data)->render();
	}
}